export function getDraggableName(eventOptions) {
  if (!eventOptions) return ''
  try {
    const componentsName = eventOptions['draggedContext']['element']['components']
    return componentsName.replaceAll('-', '')
  } catch (e) {
    return ''
  }
}
export function getDraggableTargetAttrs(eventOptions, key) {
  if (!eventOptions) return ''
  try {
    return eventOptions['relatedContext']['component']['$attrs'][key]
  } catch (e) {
    return ''
  }
}
export function getDraggableTargetName(eventOptions) {
  if (!eventOptions) return ''
  try {
    return getDraggableTargetAttrs(eventOptions, 'targetName')
  } catch (e) {
    return ''
  }
}

/**
 * @param e 拖动事件event
 * @param canDraggableFlags 可以拖拽的组件名字
 * @param target 正确的容器名字
 * */
export function isCanDraggable(e, option = { canDraggableFlags: [], target: undefined }) {
  // 获取移动的组件名称
  const draggableName = getDraggableName(e)
  // 可以实行拖拽的组件
  const condition = name => name.toLocaleUpperCase() === draggableName.toLocaleUpperCase()
  const isCanDraggedTo = option['canDraggableFlags'].length && option['canDraggableFlags'].findIndex(condition) !== -1
  // 判断是否拖拽位置是否为正确容器
  const isDraggedUseCard = option['target'] && getDraggableTargetName(e) === option['target']
  // 目标不是可用卡片容器不需要阻止
  return isCanDraggedTo ? isDraggedUseCard && isCanDraggedTo : true
}
